﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Castle.DynamicProxy;
using Moki;

namespace Moki.Core
{
    /// <summary>
    /// Encapulates member call parameters (method, arguments etc.) and number of times invoked.
    /// </summary>
    internal class CallInvocation
    {
        public CallInvocation(MethodInfo method, Arguments arguments)
        {
            this.Method = method;
            this.Arguments = arguments;
        }

        public MethodInfo Method { get; set; }
        public Arguments Arguments { get; set; }
        public int Times { get; private set; }

        public bool WasInvoked
        {
            get
            {
                return Times > 0;
            }
        }

        public void IncrementTimes()
        {
            Times++;
        }

        public override bool Equals(object obj)
        {
            if (obj is CallInvocation)
            {
                var call = (CallInvocation)obj;

                return call.Method == Method && call.Arguments.Matches(Arguments);
            }
            else
                return false;  
        }
    }
}
